package edu.gatech.asthma.ui_support;

import edu.gatech.asthma.R;

/**
 * Provides methods for dynamically acquiring resource identifiers (from R.java)
 */
public class ResourceHelper {
	
	/**
	 * Returns the resource identifier of the color with the given name
	 * @param name
	 * @return the resource identifier or zero if none exists
	 */
	public static int getColor(String name) {
		int rIdColor=0;	//resource identifier for color
		
		try {
			rIdColor = R.color.class.getField(name).getInt(null);
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (NoSuchFieldException e) {
			e.printStackTrace();
		}
		
		return rIdColor;
	}
	
	/**
	 * Returns the resource identifier of the image with the given name
	 * @param name
	 * @return the resource identifier or zero if none exists
	 */
	public static int getImage(String name) {
		int rIdImage=0;	//resource identifier for color
		
		try {
			rIdImage = R.drawable.class.getField(name).getInt(null);
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (NoSuchFieldException e) {
			e.printStackTrace();
		}
		
		return rIdImage;
	}
	
	/**
	 * Returns the resource identifier of the resource with the given name
	 * @param name
	 * @return the resource identifier or zero if none exists
	 */
	public static int getId(String name) {
		int rId=0;	//resource identifier for color
		
		try {
			rId = R.id.class.getField(name).getInt(null);
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (NoSuchFieldException e) {
			e.printStackTrace();
		}
		
		return rId;
	}
	
	/**
	 * Returns the resource identifier of the string with the given name
	 * @param name
	 * @return the resource identifier or zero if none exists
	 */
	public static int getString(String name) {
		int rId=0;	//resource identifier for color
		
		try {
			rId = R.string.class.getField(name).getInt(null);
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (NoSuchFieldException e) {
			e.printStackTrace();
		}
		
		return rId;
	}
}
